//
//  CQTextView.m
//  海成集团
//
//  Created by IOS_DEVELOPER on 2017/9/4.
//  Copyright © 2017年 海成集团. All rights reserved.
//

#import "CQTextView.h"

@interface CQTextView (){
    /** 记录初始化时的height,textview */
    CGFloat _initHeight;
}

@end

@implementation CQTextView

/** 重写初始化方法 */
- (instancetype)initWithFrame:(CGRect)frame{
    if (self = [super initWithFrame:frame]) {
        // 记录初始高度
        _initHeight = frame.size.height;
        self.clipsToBounds = NO;
        
        // 添加textView
        self.textView = [[UITextView alloc]initWithFrame:self.bounds];
        [self addSubview:self.textView];
        self.textView.delegate = (id)self;
        self.textView.backgroundColor = [UIColor clearColor];
        
        // 添加placeholderLabel
        self.placeholderLabel = [[UILabel alloc]initWithFrame:CGRectMake(3, 8, frame.size.width - 3, frame.size.height)];
        [self addSubview:self.placeholderLabel];
        self.placeholderLabel.backgroundColor = [UIColor clearColor];
        self.placeholderLabel.textColor = [UIColor lightGrayColor];
    }
    return self;
}

// 赋值placeholder
- (void)setPlaceholder:(NSString *)placeholder{
    _placeholder = placeholder;
    self.placeholderLabel.text = placeholder;
    [self.placeholderLabel sizeToFit];
    self.placeholderLabel.x = 3;
//    self.placeholderLabel.center = self.textView.center;
}

// 赋值font
- (void)setFont:(UIFont *)font{
    self.textView.font = self.placeholderLabel.font = font;
    // 重新调整placeholderLabel的大小
    [self.placeholderLabel sizeToFit];
    self.placeholderLabel.x = 3;
//    self.placeholderLabel.center = self.textView.center;
}


@end
